package com.joy.joyusers.handler;

import com.joy.joyusers.utils.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import static com.joy.joyusers.constant.HttpStatus.ERROR;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ResponseEntity<Response<String>> handleException(Exception e) {
        log.error("Exception:" + e.getMessage(), e);
        return new ResponseEntity<>(new Response<>(ERROR, e.getMessage(), null), HttpStatus.INTERNAL_SERVER_ERROR);
    }

    // You can add more exception handlers here for specific exceptions
}
